package cn.itcast.mapper;



import cn.itheima.shoppingcart.pojo.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 获取购物车数据
     *
     * @param shoppingCart 参数
     * @return 购物车
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 更新数量
     *
     * @param shoppingCart 菜品或套餐信息
     */
    @Update("update shopping_cart set number=#{number} where dish_id=#{dishId} or setmeal_id=#{setmealId}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 插入数据
     *
     * @param shoppingCart 添加的菜品或套餐信息
     */
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     *
     * @param userId 用户id
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);

    /**
     * 根据id删除购物车
     *
     * @param id
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void deleteById(Long id);
}
